package router

import (
	"github.com/starmotioncf/soutchatinternal/handler"
	"github.com/starmotioncf/soutchatinternal/middleware"

	"github.com/gin-gonic/gin"
)

type MustLoginRouter struct {
	authMiddleware        *middleware.AuthMiddleware
	rateLimitMiddleware   *middleware.RateLimitMiddleware
	maskChinaMiddleware   *middleware.MaskChinaMiddleware
	restrictionMiddleware *middleware.RestrictionMiddleware
	commonHandler         *handler.CommonHandler
	accountHandler        *handler.AccountHandler
	countryHandler        *handler.CountryHandler
}

func NewMustLoginRouter(authMiddleware *middleware.AuthMiddleware,
	rateLimitMiddleware *middleware.RateLimitMiddleware,
	maskChinaMiddleware *middleware.MaskChinaMiddleware,
	restrictionMiddleware *middleware.RestrictionMiddleware,
	commonHandler *handler.CommonHandler,
	accountHandler *handler.AccountHandler,
	countryHandler *handler.CountryHandler,
) *MustLoginRouter {
	return &MustLoginRouter{
		authMiddleware:        authMiddleware,
		rateLimitMiddleware:   rateLimitMiddleware,
		maskChinaMiddleware:   maskChinaMiddleware,
		restrictionMiddleware: restrictionMiddleware,
		commonHandler:         commonHandler,
		accountHandler:        accountHandler,
		countryHandler:        countryHandler,
	}
}

func (r *MustLoginRouter) Register(gr gin.IRouter) {
	// 注册中间件
	gr = gr.Group("",
		r.authMiddleware.ForceLoginHandler(),
		r.maskChinaMiddleware.Handle,
		r.rateLimitMiddleware.Handle,
		r.restrictionMiddleware.Handle,
	)
	//注册路由
	r.account(gr)
	r.room(gr)
	r.common(gr)
}

// account 账户
func (r *MustLoginRouter) account(gr gin.IRouter) {
	gr.GET("/profile", r.accountHandler.GetProfile)          //获取用户基本信息
	gr.POST("/refresh_token", r.accountHandler.RefreshToken) //刷新token
	gr.POST("/logout", r.accountHandler.Logout)              //退出
	gr.DELETE("/deregister", r.accountHandler.Deregister)    //注销
}

// 房间
func (r *MustLoginRouter) room(g gin.IRouter) {

}

func (r *MustLoginRouter) common(gr gin.IRouter) {
	gr.GET("/region/country", r.countryHandler.GetListByRegion) //获取国家列表，分区
	gr.GET("/presign/url", r.commonHandler.GetPresignURL)
}
